package 创建型模式.单例模式.懒汉式;

/**
 * 懒汉式只要加上synchronized锁就是安全的了
 */
class AUser 
{
//	private static AUser user;

	//同步上锁
//	public static synchronized AUser getUser() 
//	{
//		if(user == null)
//		{
//			user = new AUser();
//		}
//		return user;
//	}
	
	//上锁
	//双重检查锁定
	private static volatile AUser user;

	public static AUser getUser() 
	{
		if(user == null)
		{
			synchronized (AUser.class) {
				if (user == null) {
					user = new AUser();
				}
			}
		}
		
		return user;
	}
	
	
}